package org.lixf.biz.impl;

import org.lixf.biz.GlobalBiz;
import org.lixf.entity.Employee;
import org.lixf.mapper.EmployeeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
public class GlobalBizImpl implements GlobalBiz {

    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    @Transactional(readOnly = true)
    public Employee login(String sn, String password) {
        Employee employee = employeeMapper.select(sn);
        if (employee != null && employee.getPassword().equals(password)){
            return employee;
        }
        return null;
    }

    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
    public void changePassword(Employee employee) {
        employeeMapper.updatePassword(employee);
    }
}
